package com.qyer.commons.logger;

import static com.qyer.commons.utils.GenericConstants.SEPARATOR;

import com.qyer.commons.param.HttpParameter;
import com.qyer.commons.report.BasicTimeCost;
import org.slf4j.Logger;

/**
 * User: Z J Wu Date: 2016/04/11 Time: 17:38 Package: com.qyer.commons.logger
 */
public abstract class TimeCostLogger<P extends HttpParameter, T extends BasicTimeCost> implements
  AppendOtherInfo<T> {

  protected Logger LOGGER;

  public TimeCostLogger() {
  }

  public void logTimeCost(P p, T t) {
    if (p == null || t == null) {
      return;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(p.getRequestId());
    sb.append(SEPARATOR);
    sb.append(p.getContext());
    sb.append(SEPARATOR);
    sb.append(t.getRequestTime());
    sb.append(SEPARATOR);
    appendOtherInfo(sb, t);
    LOGGER.info(sb.toString());
  }
}
